/*
 * Copyright (c) [2005] [Jeffrey Moore]
 *
 * Redistributions in source code form must reproduce the above copyright and 
 * this condition.
 *
 * The contents of this file are subject to the Sun Project JXTA License 
 * Version 1.1 (the "License"); you may not use this file except in compliance 
 * with the License. A copy of the License is available at 
 * http://www.jxta.org/jxta_license.html.
 *
 */

/*
 * ViJxtaUtil.java
 *
 * Created on April 12, 2005, 12:20 PM
 */

package net.jxta.myjxta.plugins.vijxta;

import java.awt.Dimension;

/**
 *
 * @author Jeff Moore
 */
public class ViJxtaUtil {
    
    /** Creates a new instance of ViUtil */
    public ViJxtaUtil () {
    }
    
    public static String dimensionToString (Dimension d) {
        
        return (d != null) ?
            String.valueOf (String.valueOf ((int)d.getWidth ()) +
                " x " +
                String.valueOf ((int)d.getHeight ())) : null;
    }
    
    public static Dimension stringToDimension (String s) {
        
        
        int w = 0;
        int h = 0;
        Dimension rtn = null;
        
        if(s != null) {
            
            String[] tmp = s.split ("x");
            
            if( tmp.length == 2) {
                
                try {
                    
                    w = Integer.valueOf (tmp[0].trim ()).intValue ();
                    
                    h = Integer.valueOf (tmp[1].trim ()).intValue ();
                    
                }catch(NumberFormatException nfx) {
                    nfx.printStackTrace ();
                }
            }
            rtn = new Dimension (w,h);
        }
        return rtn;
        
    }
}
